package org.NooLab.structures.randomgraph;

import java.util.ArrayList;




public class WordPositions {
 
	
	private ArrayList<WordPosition> items = new ArrayList<WordPosition> ();
	 
	private ArrayList<String> wordlabelMap = new ArrayList<String>();
	private ArrayList<Long> fingerprintMap = new ArrayList<Long>();
	
	
	// ========================================================================
	public WordPositions(){
	}

	public WordPositions( ArrayList<WordPosition> inWP){
		items.clear();
		items.addAll(inWP) ;
	}
	// ========================================================================
	
	public void clear() {

		for (int i=0;i<items.size();i++){
			items.get(i).clear();
			items.set(i, null);
		}
		items.clear();
		items=null;
	}

	public WordPosition get(int index) {
		return getItem(index);
	}

	public WordPosition getItem(int index){
		return items.get(index) ;
	}

	public int getItemIndexByLabel(String str) {
		int p,index = -1;
		String wstr;
		
		p = wordlabelMap.indexOf(str);
		if (p>=0){
			
			if ( items.get(p).wordStr.contentEquals(str)){
				index=p;
			}else{
				for (int i=0;i<items.size();i++){
					wstr = items.get(i).wordStr;
					if (i<wordlabelMap.size()){
						wordlabelMap.set(i, wstr) ;
					}else{
						wordlabelMap.add( items.get(i).wordStr);
					}
					if ((index<0) && (wstr.contentEquals(str))){
						index=i;
					}
				} // ->
			}
		}
		
		return index;
	}

	public int getItemIndexByFingerPrintIndex( long fpIndex) {
		
		int p,index = -1;
		long fpix;
		
		p = fingerprintMap.indexOf(fpIndex);
		if (p>=0){
			
			if ( items.get(p).fingerPrintIndex == fpIndex){
				index=p;
			}else{
				for (int i=0;i<items.size();i++){
					fpix = items.get(i).fingerPrintIndex;
					if (i<fingerprintMap.size()){
						fingerprintMap.set(i, fpix) ;
					}else{
						fingerprintMap.add( items.get(i).fingerPrintIndex);
					}
					if ((index<0) && (fpIndex==i)){
						index=i;
					}
				} // ->
			}
		}
		
		return index;
	}

	
	public void add( WordPosition wordposition) {
		 
		items.add(wordposition) ;
		wordlabelMap.add( wordposition.wordStr) ;
	}

	public void remove(int i) {
		
		items.remove(i) ;
		wordlabelMap.remove(i) ;
	}

	private ArrayList<WordPosition> getItems(){
		return items;
	}
	
	public int size() {
		return items.size() ;
	}
	
}
